package at.ac.lbg.media.vis.framework.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import incboard.engine.AbstractBoard;
import incboard.engine.CellItemInterface;
import incboard.engine.HexPlacer;
import incboard.engine.itemDistanceRn;

public class ThemeLandscapeHexPlacer extends HexPlacer {

	public ThemeLandscapeHexPlacer(AbstractBoard board) {
		super(board);
        neighborSize = 6;
	}

	//
	 private CellItemInterface getNextItem(CellItemInterface item) {
	        
		 int rndIndex = (int) (Math.random() * board.itemCount());

	            Iterator<CellItemInterface> it = board.getItems().iterator();
	            
	        CellItemInterface other = it.next();
	            for (int count = 0; count < rndIndex; count++) {
	                other = it.next();

	            }
	        return other;
	    }
	 
	 private void updateNeighborsNewImplementation(CellItemInterface item) {
	/*        boolean newItem = (item.getCloseNeighbors().size() == 0);

	        item.getRandomNeighbors().clear();
	        CellItemInterface other;

	        if (!newItem) {
	            List<itemDistanceRn> oldNeighbors = new ArrayList<itemDistanceRn>();
	            for (itemDistanceRn neighbor : item.getCloseNeighbors()) {
	                if (!neighbor.other.isOnBoard()) {
	                    oldNeighbors.add(neighbor);
	                }
	            }
	            item.getCloseNeighbors().removeAll(oldNeighbors);
	        }
	        

	        while (item.getRandomNeighbors().size() < this.randomListSize) {
	            other = getRandomItem(item);
	            if (!addCloseNeighbor(item, other)) {
	                itemDistanceRn itemD = new itemDistanceRn();
	                itemD.other = other;
	                itemD.distanceR2 = board.getDistance(item, other);
	                itemD.distanceRn = item.getDistance(other);
	                item.getRandomNeighbors().add(itemD);
	            }

	        }


	        if (newItem) {    //if new item, try to improve the close list 
	            //using the closest neighbors lits'
	            itemDistanceRn previousClosestItem = null;

	            while (item.getCloseNeighbors().getFirst() != previousClosestItem) {
	                previousClosestItem = item.getCloseNeighbors().getFirst();
	                for (itemDistanceRn itemD : previousClosestItem.other.getCloseNeighbors()) {
	                    other = itemD.other;
	                    addCloseNeighbor(item, other);

	                }
	            }
	        }
	    */
	    }
}
